package com.jarvis.hospital.prescription.adapter;

import android.view.View;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.jarvis.hospital.R;
import com.jarvis.hospital.prescription.model.BloodTimeModel;
import com.jarvis.hospital.prescription.model.PrescriptionDetailModel;
import com.jarvis.hospital.prescription.model.PrescriptionTimeDetailModel;

import java.util.List;

/**
 * Created by jarvis.liu on 9/12/2016.
 */
public class PrescriptionTimeAdapter extends BaseQuickAdapter<PrescriptionTimeDetailModel> {
    public PrescriptionTimeAdapter(int layoutResId, List<PrescriptionTimeDetailModel> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PrescriptionTimeDetailModel prescriptionTimeDetailModel) {
        TextView tv_left_title = baseViewHolder.getView(R.id.tv_left_title);
        TextView tv_left_time = baseViewHolder.getView(R.id.tv_left_time);
        TextView tv_right_title = baseViewHolder.getView(R.id.tv_right_title);
        TextView tv_right_time = baseViewHolder.getView(R.id.tv_right_time);
        ImageView img_center = baseViewHolder.getView(R.id.img_center);
        LinearLayout lin_left = baseViewHolder.getView(R.id.lin_left);
        LinearLayout lin_right = baseViewHolder.getView(R.id.lin_right);

        if ("0".equals(prescriptionTimeDetailModel.getIsPlan())) {
            lin_left.setVisibility(View.VISIBLE);
            lin_right.setVisibility(View.GONE);
            tv_left_title.setText(prescriptionTimeDetailModel.getItemName());
            tv_left_time.setText(prescriptionTimeDetailModel.getItemTime());
        } else {
            lin_left.setVisibility(View.GONE);
            lin_right.setVisibility(View.VISIBLE);
            tv_right_title.setText(prescriptionTimeDetailModel.getItemName());
            tv_right_time.setText(prescriptionTimeDetailModel.getItemTime());
        }
        if (baseViewHolder.getLayoutPosition() == 0) {
            Glide.with(mContext)
                    .load(R.drawable.img_time_green)
                    .error(R.drawable.img_main_bg)
                    .into(img_center);
            tv_right_title.setTextColor(mContext.getResources().getColor(R.color.green));
            tv_right_time.setTextColor(mContext.getResources().getColor(R.color.green));
            tv_left_title.setTextColor(mContext.getResources().getColor(R.color.green));
            tv_left_time.setTextColor(mContext.getResources().getColor(R.color.green));
        }else {
            Glide.with(mContext)
                    .load(R.drawable.img_time_gray)
                    .error(R.drawable.img_main_bg)
                    .into(img_center);
            tv_right_title.setTextColor(mContext.getResources().getColor(R.color.text_gray));
            tv_right_time.setTextColor(mContext.getResources().getColor(R.color.text_gray));
            tv_left_title.setTextColor(mContext.getResources().getColor(R.color.text_gray));
            tv_left_time.setTextColor(mContext.getResources().getColor(R.color.text_gray));
        }
    }
}
